<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');


class Welcome extends Controller{
  
  	function Welcome(){
    	parent::Controller();
     
  	}
  
  	/**
	* Array of languages supported by the installer
	*/
	private $languages	= array ('arabic', 'english',  'french');
 
  	/**
	 * Index method
	 * 
	 * @access public
	 * @return void
	 */
	public function index()
	{  
		// Sets the language
		$this->_set_language();  
		$data['page_output'] 		= $this->parser->parse('main', $this->lang->language, TRUE);		
		
		//load the mission statment    		
		$this->lang->load('missionstatement');
		$this->load->helper('text');     		
		$data['mission_statement_full_page'] = false;
		
		
		
		
		//load the videos
		$this->load->model('Videos_model');   
		$this->load->helper('text');     		
		$this->lang->load('videos');
		$videopage = $this->uri->segment(4); 
		$video_data['videos'] 		= $this->Videos_model->get_videos_with_top_rated($videopage); 
		$video_data['totalVideos'] 	= $this->Videos_model->get_total_videos(); 
		$video_data['strings'] 		= $this->lang->language;  
		// Load the view file
		
			
	    $data['page_output'] 		.= '<table><tr><td>'; 
	    $data['page_output'] 		.= $this->parser->parse('missionstatement', $data, TRUE);
	    $data['page_output'] 		.= '</td><td>';  	
	    $data['page_output'] 		.= '<table><tr><td><div class="follow" ></div></td>';
	    $data['page_output'] 		.= '<td><div class="facebook-logo"></div></td></tr></table>';
	    $data['page_output'] 		.= '<div style="margin-left:20px"><fb:like></fb:like></div>';  
	    $data['page_output'] 		.= '</td></tr><tr><td>';
	    $data['page_output'] 		.= $this->parser->parse('videos', $video_data, TRUE); 	
	    $data['page_output'] 		.= '</td><td>';  	
	    $data['page_output'] 		.= '<script src="http://widgets.twimg.com/j/2/widget.js"></script><script>new TWTR.Widget({  version: 2,  type: "profile",  rpp: 4,  interval: 6000,  width: 400,  height: 300,  theme: {    shell: {      background: "#ffffff",      color: "#ababab"    },    tweets: {      background: "#ffffff",      color: "#a19fa1",      links: "#4aed05"    }  },  features: {    scrollbar: false,    loop: false,    live: false,    hashtags: true,    timestamp: true,    avatars: false,    behavior: "all"  }}).render().setUser("tunisien").start();</script>';  	
	    $data['page_output'] 		.= '</td></tr></table>';
	     
		$this->load->view('global',$data); 
	}
	 
	
	public function mission_statement()
	{
		$this->_set_language();  
		$data['page_output'] 		= $this->parser->parse('main', $this->lang->language, TRUE);
		$data['mission_statement_full_page'] = true;
		//load the mission statment    		
		$this->lang->load('missionstatement');
		$this->load->helper('text');     		
	    $data['page_output'] 		.= $this->parser->parse('missionstatement', $data, TRUE); 	
		
		// Load the view file
		$this->load->view('global',$data);
	}
	
	public function QnA()
	{
		$this->_set_language(); 
		$query = $this->db->get('qna_'.$this->session->userdata('language'));    
	    $data_temp = array( 
	              'qna' => $query->result_array()
	     );
		$data['page_output'] = $this->parser->parse('qna', $this->lang->language, TRUE);	
	    $data['page_output'] .= $this->parser->parse('qna_template', $data_temp, TRUE); 	 
		$this->load->view('global',$data);
	}
	
	/**
	 * Changes the active language
	 *
	 * @access	public
	 * @author	jeroenvdgulik
	 * @since	0.9.8.1
	 * @param	string $language
	 * @return	void
	 */
	public function change($language)
	{
		if (in_array($language, $this->languages))
		{
			$this->session->set_userdata('language', $language);
		}

		redirect('welcome');
	}
	/**
	 * Sets the language and loads the corresponding language files
	 *
	 * @access	private
	 * @author	jeroenvdgulik
	 * @since	0.9.8.1
	 * @return	void
	 */
	private function _set_language()
	{
		
		if(!$this->session->userdata('language')  )
		{
			$this->config->set_item('language', 'english');
			$this->session->set_userdata('language', 'english');
		}
			
		// let's check if the language is supported
		if (in_array($this->session->userdata('language'), $this->languages))
		{
			// if so we set it
			$this->config->set_item('language', $this->session->userdata('language'));
		}

		// let's load the language file belonging to the page i.e. method
		$lang_file = $this->config->item('language') . '/' . $this->router->fetch_method() . '_lang';
		if (is_file(realpath(dirname(__FILE__) . '/../language/' . $lang_file . EXT)))
		{
			$this->lang->load($this->router->fetch_method());
		}

		// also we load some generic language labels
		$this->lang->load('global');
	} 
	
}

?>